<?php
include("function.php");

if($_GET['request']==1){
	$data = array();
	$n=0;
	$edit=0;
	$re=mysql_query("select * from `gallery` where `user`='$_GET[user]'")or die(mysql_error());
	while($row=mysql_fetch_array($re)){
		if($_SESSION['login_mail']==$row['user'])$edit=1;
		$data[$n][] = array("gallery" => $row['name'],"id" => $row['id'],"edit" => $edit);
		$result=mysql_query("select * from `image` where gallery='$row[id]' and `del`='0' limit 0,9");
		while($r=mysql_fetch_array($result)){
			$img="image.php?id=".$r['id']."&type=small";
			$data[$n][] = array("img" => $img);
		}
		$n++;
	}
	echo json_encode($data);
	//var_dump($data);
}

if($_POST['request']==2){
	$x=mysql_query("update `gallery` set `name`='$_POST[album_name]' where `id`='$_POST[id]'")or die(mysql_error());
	echo "yes";
}

if($_GET['request']==3){
	$x=mysql_query("update `image` set `del`='1' where `gallery`='$_GET[id]'")or die(mysql_error());
	$x=mysql_query("delete from `gallery` where `id`='$_GET[id]'") or die(mysql_error());
	echo "yes";
}
?>